package com.chenzhengrong.demospringboot.hutooltest;

import cn.hutool.core.date.*;
import cn.hutool.core.lang.Console;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author chenzhengrong
 * @title: TesetHutool
 * @description: TesetHutool
 * @date 2022/10/14 14:52
 */
@Slf4j
public class TesetHutool {

    @Test
    void demo() throws UnsupportedEncodingException {
        byte[] bytes = "czr".getBytes("UTF-8");
        for (int i = 0; i < bytes.length; i++) {
            System.out.println(bytes[i]);
        }
    }

    @Test
    public void test() {
        Date date = DateUtil.date();
        date.toString();
        log.info("date：{}", date);
        LocalDateTime localDateTime = LocalDateTimeUtil.parse("2020-01-23T12:23:56");
        // 增加一天
        // "2020-01-24T12:23:56"
        LocalDateTime offset = LocalDateTimeUtil.offset(localDateTime, 1, ChronoUnit.DAYS);
        String format = LocalDateTimeUtil.format(offset, DatePattern.NORM_DATETIME_PATTERN);
        log.info("offset：{}", offset);
    }

    @Test
    public void testTaskTime() {

        final TimeInterval timer = new TimeInterval();

        // 分组1
        timer.start("1");
        ThreadUtil.sleep(800);

        // 分组2
        timer.start("2");
        ThreadUtil.sleep(900);

        Console.log("Timer 1 took {} ms", timer.intervalMs("1"));
        Console.log("Timer 2 took {} ms", timer.intervalMs("2"));

    }

    @Test
    public void test1() {
        String appcode = "1279f7db4caa4a7d9dc098a94190d7ee";

        //链式构建请求
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("area", "济南");
        //paramMap.put("areaid", "101120101");
        String result = HttpRequest.get("https://qryweather.market.alicloudapi.com/lundroid/queryweather")
                .header("Authorization", "APPCODE" + appcode) //头信息，多个头信息多次调用此方法即可
                .form(paramMap)//表单内容
                .timeout(20000)//超时，毫秒
                .execute().body();
        Console.log(result);
    }

}
